#pragma once

#include "McuRPCBuffer.h"
#include "BufferQueue.h"
#include <utils/Thread.h>
#include "Barrier.h"
#include "McuRPCHandler.h"

namespace android {

class McuRPCManager;

class DispatcherThread: public Thread {
public:
    DispatcherThread(McuRPCManager* manager, int hw_type, BufferQueue<McuRPCBuffer>* queue);
    ~DispatcherThread();
    void start();
    void stop();
    void onDataReady();
    void registerRPCHandler(McuRPCHandler* handler);

private:
    virtual bool threadLoop() override;
    int processWheelControl(McuRPCBuffer* buf);

    BufferQueue<McuRPCBuffer>* mBufferQueue;
    McuRPCManager* mManager;
    McuRPCHandler* mHandler;

    mutable Barrier mBarrier;
    int mHwType;
};

}//namespace
